/**
 * Wihidum - Efficient Broker Hierarchy for Publish Subscribe Middleware
 *
 * License      :   Apache License 2.0
 * Home Page    :   http://code.google.com/p/wihidum/
 * Mailing List :   wihidum@googlegroups.com
 */

package lk.mrt.cse.wihidum.storage;

import org.apache.log4j.*;
import org.hibernate.*;

/**
 * Access data about publications in database
 */
public class PublicationDAO
        implements PublicationManager
{

    Session session = null;
    private static final Logger logger = Logger.getLogger (PublicationDAO.class);

    /**
     * Default constructor
     */
    public PublicationDAO ()
    {
        this.session = DataBaseManager.getSessionFactory ().getCurrentSession ();
    }

    /**
     * @see lk.mrt.cse.wihidum.storage.PublicationManager#savePublication(Publication)
     */
    public boolean savePublication (Publication publication)
    {
        try
        {
            Transaction tx = session.beginTransaction ();
            session.save (publication);
            tx.commit ();
            logger.info ("Publication saved successfully");
            return true;
        }
        catch (HibernateException ex)
        {
            logger.error ("Error in saving publication", ex);
            return false;
        }
    }
}
